﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.Data.API.Write.Applicant.Command.RoleInfo;
using MS.Data.Domain;
using MS.Data.ErrorCode;

namespace MS.Data.API.Write.Controllers
{
    /// <summary>
    /// API控制器-写 角色
    /// </summary>
    [Route("api/[controller]/[action]")]

    [ApiController]
    public class MngRoleController : ControllerBase
    {
        IMediator mediator;

        public MngRoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddRole(AddRoleCommand add)
        {
            return await mediator.Send(add);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<int>> DelRole([FromQuery] DelRoleCommand del)
        {
            return await mediator.Send(del);
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="ening"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<Role>>> Fening([FromQuery] FeningCommand ening)
        {
            return mediator.Send(ening);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateRole(UpdateCommand role)
        {
            return await mediator.Send(role);
        }
    }
}
